// 下面这个代码处理过度动画（默认加上不用管）
document.addEventListener('DOMContentLoaded', () => {
  setTimeout(() => {
    document.body.classList.add('sidenav-pinned')
    document.body.classList.add('ready')
  }, 200)
})
axios.defaults.baseURL='http://ajax-api.itheima.net'
axios.defaults.headers.common['Authorization']=localStorage.getItem('user-token')

// axios.interceptors.request.use(
//   function(config){
//     config.headers.Authorization=localStorage.getItem('user-token')
//     return config
//   },
//   function(error){
//     return Promise.reject(error)
//   }
// )
axios.interceptors.response.use(
  function(response){
    return response
  },
  function(error){
    // alert(error.response.data.message)
    tip(error.response.data.message)
    if(error.response.status===401){
      localStorage.removeItem('user-name')
      localStorage.removeItem('user-token')
      location.href='./login.html'
    }
    // console.log(error.response.data.message);
    return Promise.reject(error)
  }
)
function tip(msg){
  let div=document.querySelector('#myToast')
  let toast=new bootstrap.Toast(div)
  div.querySelector('.toast-body').innerHTML=msg
  toast.show()
}
